<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class manufacturer extends CI_Controller {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );

    function __construct() {
        parent::__construct();
        $this->load->model("muser");
        $this->load->model("mmanufacturer");
        $this->load->model("mresource");
		
		$this->resCode = $this->mmanufacturer->resCode;
        $this->url_index = admin_url() . "manufacturer";
        $this->url_edit = $this->url_index . "/edit/";
        $this->url_delete = $this->url_index . "/delete/";
        $this->url_add = $this->url_index . "/edit/0";
    }

    public function index() {
        $data = array();
        $data['datas'] = $this->mmanufacturer->gets();
        $data['tresource'] = $this->mresource->get($this->resCode,'RES_CODE');
        $this->theme_data["main"] = "manufacturer/index";
        $this->template->viewAdmin($this->theme_data, $data);
    }

    function edit($manID = 0) {
        $data = array();
        $post = $this->input->post();
        $data['dep'] = $this->mmanufacturer->get($manID, 'MAN_ID');
		$data['tresource'] = $this->mresource->get($this->resCode,'RES_CODE');
        $data['error'] = array('err_code' => 0, 'msg' => '');
        if ($post) {
            if ($manID > 0) {
                $this->mmanufacturer->update($manID, 'MAN_ID', $post['dep']);
            }
			else{
				$manID = $this->mmanufacturer->insert($post['dep']);
			}
            redirect($this->url_edit . $manID);
        }

        $this->theme_data["main"] = "manufacturer/edit";
        $this->template->viewAdmin($this->theme_data, $data);
    }
	
	function delete($manID = 0){
		if($manID > 0){
			$this->mdepartmental->delete($manID, 'MAN_ID');
		}
	}
}
